package com.atguigu.jxc.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.jxc.dao.DamageListGoodsDao;
import com.atguigu.jxc.dao.OverflowListGoodsDao;
import com.atguigu.jxc.entity.*;
import com.atguigu.jxc.service.OverflowListGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * ClassName: OverflowListGoodsServiceImpl
 * Description:
 * Date: 2022/1/17 0:06
 *
 * @version:
 * @since JDK 1.8
 */
@Service
public class OverflowListGoodsServiceImpl implements OverflowListGoodsService {
    @Autowired
    private OverflowListGoodsDao overflowListGoodsGoodsDao;


    @Override
    public void saveOverflowListGoods(OverflowList overflowList, String overflowListGoodsStr, HttpSession session) {


        User user = (User)session.getAttribute("currentUser");
        overflowList.setUserId(user.getUserId());
        overflowListGoodsGoodsDao.saveOverflowList(overflowList);



        List<OverflowListGoods> goodsList = JSONObject.parseArray(overflowListGoodsStr, OverflowListGoods.class);

        for (OverflowListGoods overflowListGoods : goodsList) {
            overflowListGoods.setOverflowListId(overflowList.getOverflowListId());
            overflowListGoodsGoodsDao.saveOverflowGoods(overflowListGoods);
        }
    }


    @Override
    public List<OverflowList> getOverflowListGoods(String sTime, String eTime) {
        List<OverflowList> overflowListList = overflowListGoodsGoodsDao.getOverflowListGoods(sTime,eTime);
        return overflowListList;
    }


    @Override
    public List<OverflowListGoods> getGoodsList(Integer overflowListId) {
        List<OverflowListGoods> overflowListGoodsList = overflowListGoodsGoodsDao.getGoodsList(overflowListId);
        return overflowListGoodsList;
    }





}
